<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>群组列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">

<script type="text/html" id="topOperate">
    <div class="my-btn-box layui-form">
      <!--<span class="fl"> -->
    <!--<button class="layui-btn layui-btn-sm" lay-event="toSave"><i-->
            <!--class="layui-icon"></i>添加用户</button>-->
    <!--</span>-->

    </div>
</script>

<div class="my-btn-box layui-form">
    <span class="fr">
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="name" placeholder="搜索群名称" class="layui-input height33">
        </div>
        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , $ = layui.jquery;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'user.id', title: 'ID', minWidth: 100, sort: true, align: 'center', templet: function (d) {
                    return d.id;
                }
                },
                {field: 'groupIdEncryption', title: 'ID秘文', minWidth: 100, sort: true, align: 'center'}
                , {
                    field: 'user.username', title: '群头像', align: 'center', minWidth: 100, templet: function (d) {
                        if(d.imgurl==null){
                            return "暂无";
                        }
                        return "<img src='"+d.imgurl+"'>";
                    }
                }
                , {
                    field: 'user.username', title: '群名称', align: 'center', minWidth: 100, templet: function (d) {
                        return d.name;
                    }
                },
                {field: 'creatorid', title: '群主ID', align: 'center', minWidth: 100},
                {field: 'groupLeaderName', title: '群主名称', align: 'center', minWidth: 100},
                {
                    field: 'user.username', title: '群描述', align: 'center', minWidth: 100, templet: function (d) {
                        return d.descri==null?"":d.descri;
                    }
                }

                , {
                    field: 'user.ctime',
                    align: 'center',
                    title: '创建时间',
                    sort: true,
                    width: "15%",
                    templet: function (d) {
                        return new Date(parseInt(d.timestamp)).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }
                , {
                    title: '操作', align: 'center',minWidth: 250, templet: function (d) {
                        var html = " <a class=\"layui-btn layui-btn-normal layui-btn-xs\" lay-event=\"groupMember\"><i class=\"layui-icon layui-icon-speaker\"></i>群组成员</a>"
                        if (d.ismute == 3) {
                            html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs\" lay-event=\"toggleMute\"><i class=\"layui-icon layui-icon-play\" style=\"cursor: pointer\"></i>解封</a>";
                        } else {
                            html += "<a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"toggleMute\"><i class=\"layui-icon layui-icon-pause\" style=\"cursor: pointer\"></i>封禁</a>";
                        }
                        html += "<a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"dismiss\"><i class=\"layui-icon layui-icon-unlink\" style=\"cursor: pointer\"></i>解散</a>";
                        return html;
                    }
                } //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/group/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // ,where:{name:$("input[name='name']").val()}
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });


            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;

            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '用户增加',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['650px', '550px'],
                        content: [[${basePath}]] + '/user/save/index'
                    });
                    break;
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            console.log(obj.data);
            if (obj.event === 'groupMember') {

                layer.open({
                    type: 2,
                    title: '群组成员',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['100%', '100%'],
                    content: [[${basePath}]] + '/group/member/index?gid=' + data.id
                });

            }
            if (obj.event === 'toggleMute') {
                var content = data.ismute == 3 ? "解封" : "封禁";
                layer.confirm("确定"+content+"该群吗?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/group/mute",
                        data: {groupId: data.id, status: data.ismute == 3 ? 4 : 3},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("操作成功！", {icon: 1}, 1000);
                                setTimeout(function () {
                                    $("#search").click();
                                },1000);
                            }else{
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });
                });
            }
            //解散群
            if (obj.event === 'dismiss') {
                layer.confirm("确定解散该群吗?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/group/dismiss",
                        data: {groupId: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("解散成功！", {icon: 1}, 1000);
                                setTimeout(function () {
                                    $("#search").click();
                                },1000);
                            }else{
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });


                });
            }
        });

        $("#search").click(function () {
            tableIns.reload({
                where: {name: $("input[name='name']").val()},
                page: {
                    curr: 1
                }
            });
        })


    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <i class="layui-icon layui-icon-list" style="cursor: pointer" lay-event="groupMember" title="群组成员"></i>
    <!--<i class="layui-icon layui-icon-edit" lay-event="edit"></i>-->
</script>
</body>
</html>